//
//  File_Name_Path.m
//  MacStockApp
//
//  Created by 英傑 翁 on 12/6/14.
//  Copyright (c) 2012年 翁英傑. All rights reserved.
//

#import "File_Name_Path.h"
#import "GBall.h"

@implementation File_Name_Path

#pragma mark -
#pragma mark Target_Version 格式

+(NSString *)string_Target_Version{
    NSString *productName;
    productName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
    
    NSString *version;
    version=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    NSArray *copm=[version componentsSeparatedByString:@"."];
    
    
    return  [ NSString  stringWithFormat: @"(%@)_(%@_%@)",productName,[copm objectAtIndex:0],[copm objectAtIndex:1] ];
    
}

+(NSString *)string_Target{
    NSString *productName;
    productName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
   
    
    return  [ NSString  stringWithFormat: @"(%@)",productName ];
    
}

#pragma mark -
#pragma mark RealFromResource 版本檔名 不含副檔名
 
//RLCalculationMethod
+(NSString *)file_name_RLCalculationMethod{
    
    return [ NSString  stringWithFormat: @"RLCalculationMethod_%@", [self string_Target]  ];
    
}
//RLTableColumnHeader
+(NSString *)file_name_RLTableColumnHeader{
    
    return [ NSString  stringWithFormat: @"RLTableColumnHeader_%@", [self string_Target_Version]  ];
    
}
//RLChartMenuItem
+(NSString *)file_name_RLChartMenuItem{
    
    return [ NSString  stringWithFormat: @"RLChartMenuItem_%@", [self string_Target_Version]  ];
    
}




#pragma mark -
#pragma mark ReadFromDevice 版本檔名 不含副檔名

//sqlite_TV
+(NSString *)file_name_sqlite{
    
    return [ NSString  stringWithFormat: @"SQLITE3_%@", [self string_Target_Version]  ];
    
}

//ChartMenu_TV
+(NSString *)file_name_ChartMenuItem{
    
    return [ NSString  stringWithFormat: @"CM_%@", [self string_Target_Version]  ];
    
}

//TableColumn_TV
+(NSString *)file_name_TableColumn{
    
    return [ NSString  stringWithFormat: @"TCD_%@", [self string_Target_Version]  ];
    
}

//TableColumnGroup_T
+(NSString *)file_name_TableColumnGroup{
    
    return [ NSString  stringWithFormat: @"TCGE_%@", [self string_Target]  ];
    
}

//Watchlist_T
+(NSString *)file_name_Watchlist{
    
    return [ NSString  stringWithFormat: @"PSW_%@", [self string_Target]  ];
    
}
//Watchlist_System_T
+(NSString *)file_name_Watchlist_System{

     return [ NSString  stringWithFormat: @"PSW_System_%@", [self string_Target_Version]  ];    
}


#pragma mark -
#pragma mark 走勢圖的選項存放路徑
+(NSString*)RLChartMenuItem_file_name:(NSString *)datasource add_plist:(BOOL)add_plist{
   
    
    
    if (add_plist) {
       //增加 .plist 檔案全名
        return [ NSString  stringWithFormat: @"%@.plist",[self file_name_ChartMenuItem] ] ;
    }
    else {
        return [self file_name_ChartMenuItem]  ;
    }
   
} 

+(NSString*)RLChartMenuItem_file_nameANDpath:(NSString *)datasource{
    
    //存放路徑位置與檔名  
    NSString *filename;
    
    //路徑名稱    
    { 
        
        
        //3.製作檔名
        filename=[ NSString  stringWithFormat: @"%@.plist",[self file_name_ChartMenuItem] ];
        
        
        //4.取出存放位置的檔案路徑
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
        NSString *Path_Table_column  ; 
        Path_Table_column=[prefs objectForKey:Defaults_Path_Chart_Menu_Item];              
        
        
        //5.回傳合成為(路徑+名稱)
        return  [[[NSString alloc] initWithString:[Path_Table_column stringByAppendingPathComponent:filename]] autorelease];        
        
        
    }
    
    
}

#pragma mark -
#pragma mark 報價表頭
+(NSString*)RLTableColumnHeader_file_name:(NSString *)datasource add_plist:(BOOL)add_plist{
  
           
    
    if (add_plist) {
        //增加 .plist 檔案全名
        return [ NSString  stringWithFormat: @"%@.plist", [self file_name_TableColumn] ] ;
    }
    else {
        return [self file_name_TableColumn]  ;
    }
}
+(NSString*)RLTableColumnHeader_file_nameANDpath:(NSString *)datasource{
    //存放路徑位置與檔名  
    NSString *filename;
    
    //路徑名稱    
    {
        
        //1.取出版本
        
        
        //3.製作檔名
        filename=[ NSString  stringWithFormat: @"%@.plist",[self file_name_TableColumn] ];
        
        
        //4.取出存放位置的檔案路徑
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
        NSString *Path_Table_column  ; 
        Path_Table_column=[prefs objectForKey:Defaults_Path_Table_column];              
        
        
        //5.回傳合成為(路徑+名稱)
        return  [[[NSString alloc] initWithString:[Path_Table_column stringByAppendingPathComponent:filename]] autorelease];        
        
        
    }
    
    
    
}

 
#pragma mark -
#pragma mark sqlite 資料庫
 
//資料庫的位置與名稱
+(NSString *)sqlite_database_path_name:(BOOL) ishave_sqlite3{
    
    
    //sqlite 檔名
    NSString *fullfilename;
    fullfilename=[NSString stringWithFormat:@"%@.sqlite3",[self file_name_sqlite]];
    
    NSString *fullfilename_no_sqlite3;
    fullfilename_no_sqlite3=[self file_name_sqlite];
     
    
    //sqlite 檔案路徑
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *Path_Sqlite_Data  ;
    Path_Sqlite_Data=[prefs objectForKey:Defaults_Path_Sqlite_Data];
    
    
    //設定資料庫位置
    NSString *sqlite_path_name;
   
    
    if (ishave_sqlite3) {
        sqlite_path_name =[Path_Sqlite_Data stringByAppendingPathComponent: fullfilename];
    }
    else{
        sqlite_path_name =[Path_Sqlite_Data stringByAppendingPathComponent: fullfilename_no_sqlite3];
    
    }
    
   
    return sqlite_path_name;
    

}

@end
